package com.ly.system.system.bean.model;

import cn.hutool.core.util.ObjUtil;
import com.ly.system.system.bean.entity.SysPermission;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 菜单tree
 *
 * @author jeecg
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class SysPermissionTree implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    private String id;
    private String key;
    private String title;

    /**
     * 父id
     */
    private String parentId;

    /**
     * 菜单名称
     */
    private String name;

    /**
     * 父菜单名称
     */
    private String parentName;

    /**
     * 菜单权限编码
     */
    private String perms;
    /**
     * 权限策略1显示2禁用
     */
    private String permsType;

    /**
     * 菜单图标
     */
    private String icon;

    /**
     * 组件
     */
    private String component;

    /**
     * 组件名字
     */
    private String componentName;

    /**
     * 跳转网页链接
     */
    private String url;

    /**
     * 一级菜单跳转地址
     */
    private String redirect;

    /**
     * 菜单排序
     */
    private Double sortNo;

    /**
     * 类型（0：一级菜单；1：子菜单 ；2：按钮权限）
     */
    private Integer menuType;

    /**
     * 是否叶子节点: 1:是 0:不是
     */
    private Boolean isLeaf;

    /**
     * 是否路由菜单: 0:不是  1:是（默认值1）
     */
    private Boolean route;

    /**
     * 是否路缓存页面: 0:不是  1:是（默认值1）
     */
    private Boolean keepAlive;

    /**
     * 描述
     */
    private String description;

    /**
     * 删除状态 0正常 1已删除
     */
    private Integer delFlag;

    /**
     * 创建人
     */
    private String createBy;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新人
     */
    private String updateBy;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * alwaysShow
     */
    private Boolean alwaysShow;
    /**
     * 是否隐藏路由菜单: 0否,1是（默认值0）
     */
    private Boolean hidden;

    /**
     * 按钮权限状态(0无效1有效)
     */
    private java.lang.String status;

    /**
     * 外链菜单打开方式 0/内部打开 1/外部打开
     */
    private Boolean internalOrExternal;

    /**
     * 是否隐藏Tab: 0否,1是（默认值0）
     */
    private Boolean hideTab;

    private List<SysPermissionTree> children;

    public SysPermissionTree(SysPermission permission) {
        this.key = permission.getId();
        this.id = permission.getId();
        this.parentId = permission.getParentId();
        this.name = permission.getName();
        this.parentName = permission.getParentName();
        this.perms = permission.getPerms();
        this.permsType = permission.getPermsType();
        this.component = permission.getComponent();
        this.componentName = permission.getComponentName();
        this.createBy = permission.getCreateBy();
        this.createTime = permission.getCreateTime();
        this.delFlag = permission.getDelFlag();
        this.description = permission.getDescription();
        this.icon = permission.getIcon();
        this.isLeaf = permission.getLeaf();
        this.menuType = permission.getMenuType();
        this.sortNo = permission.getSortNo();
        this.updateBy = permission.getUpdateBy();
        this.updateTime = permission.getUpdateTime();
        this.redirect = permission.getRedirect();
        this.url = permission.getUrl();
        this.hidden = permission.getHidden();
        this.route = permission.getRoute();
        this.keepAlive = permission.getKeepAlive();
        this.alwaysShow = permission.getAlwaysShow();
        this.internalOrExternal = permission.getInternalOrExternal();
        this.title = permission.getName();
        this.hideTab = permission.getHideTab();
        if (ObjUtil.notEqual(permission.getLeaf(), true)) {
            this.children = new ArrayList<SysPermissionTree>();
        }
        this.status = permission.getStatus();
    }
}
